package Java实训.第三天JDK特性流;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class Num2 {
    /*
    * 给一个整数集合，将集合分成偶数集合和奇数集合
    * */
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < 20; i++) {
            list.add(random.nextInt(10));
        }
        System.out.println("整体集合为: " + list);
        List<Integer> list1 = list.stream().filter(s -> s % 2 == 0).collect(Collectors.toList());
        List<Integer> list2 = list.stream().filter(s -> s % 2 != 0).collect(Collectors.toList());
        System.out.println("偶数集合为: " + list1);
        System.out.println("奇数集合为: " + list2);
    }
}
